package testing;


import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;
import logicaDePredicados.LogicOperatorFactory;
import logicaDePredicados.LogicPredicate;
import logicaDePredicados.Pair;
import logicaDePredicados.PredicateConstant;
import logicaDePredicados.PredicateVariable;
import org.junit.Before;
import org.junit.Test;
import com.db4o.Db4o;
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.config.Configuration;
import com.db4o.internal.config.EmbeddedConfigurationImpl;
import com.db4o.query.Predicate;

import exceptions.UnBalancedExpressionException;
import exceptions.UnDecidibleValueException;
import logicaDePredicados.Sentence;

public class DbSentenceTest {
	private LogicPredicate<String> animal;
	private LogicPredicate<String> mammal;
	private PredicateConstant<String> perro;
	private PredicateConstant<String> helecho;
	private Sentence sentencia ;
	private LogicPredicate<String> dog;
	private PredicateVariable <String> x ;
	private LogicPredicate<String> bird; 
	private LogicPredicate<Pair<String,String>> loves;
	private LogicPredicate<Pair<String,String>> hates;
	ArrayList<LogicPredicate<?>> predicados;
	/**
	 * @throws Exception
	 */
	/**
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
//		
		ObjectContainer container = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(), "./tpfinal/base/base.yap");
		try{
			
		List<LogicPredicate<?>> resultset = container.query(new predicatesAndQuerys.RetrieveAllLogicPredicates());
		predicados = new ArrayList<LogicPredicate<?>>();
		for (LogicPredicate<?> logicPredicate : resultset) {
			predicados.add(logicPredicate);
		}
		}catch (Exception e) {


		}finally {
			container.rollback();
			container.close();
		}
		
		
		
	}
	/**
	 * @throws UnDecidibleValueException 
	 * 
	 */
	/**
	 * @throws UnDecidibleValueException
	 * @throws UnBalancedExpressionException 
	 */
	@Test
	public void testCase () throws UnDecidibleValueException, UnBalancedExpressionException{

		PredicateConstant<Pair<String,String>> juanMaria = new PredicateConstant<Pair<String,String>>(new Pair<String, String>("John","Mary"));
		PredicateConstant<Pair<String, String>> juanPedro = new PredicateConstant<Pair<String,String>>(new Pair<String, String>("John","Peter"));
		System.out.println(predicados);
//		sentencia.add(predicados.);
//		sentencia.add(juanMaria);
//		sentencia.add(LogicOperatorFactory.createAND());
//		sentencia.add(hates);
//		sentencia.add(juanPedro);
//		System.out.println(sentencia.rawFormat());
//		Assert.assertEquals(true, parser.LogicParser.parseSentence(sentencia));
		
		
	}

}
